const search = new Vue({
    el:"#index-search",
    data:{
       text:"",
       songs:[],
       musicUrl:"",
       activeMusicId:"",
       seen:false,
       singerUrl:""
    },
    methods:{
        search(){
            if(!this.text) {
                alert("关键字不能为空")
                return
            }
            this.seen = true
            fetch(`http://localhost:3000/search?keywords=${this.text}`).then(res => res.json()).then(res =>{
                const { songs } = res.result
                this.songs = songs
            }).catch(e => {
                console.log(e)
            }).finally(()=>{this.seen=false})
        },
        playAudio(id){
            this.musicUrl = `https://music.163.com/song/media/outer/url?id=${id}.mp3`
            this.activeMusicId = id
        },
        getSingerId(id,name){
            this.singerUrl = `./singer.html?id=${id}&name=${name}`
        },
        skipTo(){
            window.location.href = "./all-singers.html"
        }
    }
})